<template>
  <div class="problemList">
    <div class="addMargin">
      <el-button class="increased" icon="el-icon-plus" @click="addUser('录入机房巡检单')">录入机房巡检单</el-button>
      <el-form :inline="true" class="formLine">
        <el-form-item class="formLine_item" label="所属机构：">
          <el-select v-model="searchBox.ssjg" :no-data-text="tiText1" clearable placeholder="选择机构">
            <el-option v-for="item in jgmcOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="巡检时间:" class="formLine_item">
          <el-date-picker
            v-model="searchBox.xjsj"
            :picker-options="pickerBeginDateBefore"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-form-item>
        <el-form-item class="formLine_item">
          <el-input v-model="searchBox.searchValue" clearable placeholder="输入巡检人姓名" prefix-icon="el-icon-search"></el-input>
        </el-form-item>
        <el-form-item class="formLine_item">
          <el-button type="primary">查询</el-button>
          <!-- <el-button plain type="primary">打印</el-button> -->
        </el-form-item>
      </el-form>
    </div>
    <el-table
      border
      :header-cell-style="{ backgroundColor: '#ECF3FC', color: '#333', height: '48px', borderBottom: '1px solid #CEE1F7' }"
      highlight-current-row
      ref="multipleTable"
      :data="contractList"
      style="width: 100%"
      :default-sort="{ prop: 'deviceName' }"
    >
      <el-table-column prop="qdrq" label="所属机构" show-overflow-tooltip min-width="150"></el-table-column>
      <el-table-column prop="qdrq" label="机房温度">
        <template slot-scope="scope">
          <span>{{ scope.row.qdrq }}°</span>
        </template>
      </el-table-column>
      <el-table-column prop="qdrq" label="空调状态">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="scope.row.qdrq === 1 ? '关闭' : '开启'" placement="top">
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.qdrq === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
          </el-tooltip>
          <!-- <svg
            v-show="scope.row.qdrq === 1 ? false : true"
            class="iconfont"
            style="width: 12px;height: 12px;vertical-align: middle;"
          >
            <use xlink:href="#el-icon-mygenerated" style="font-size:50px" />
          </svg>
          <svg
            v-show="scope.row.qdrq === 1 ? true : false"
            class="iconfont"
            style="width: 12px;height: 12px;vertical-align: middle;"
          >
            <use xlink:href="#el-icon-mywarning" style="font-size:50px" />
          </svg>-->
        </template>
      </el-table-column>
      <el-table-column label="新风状态" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="scope.row.qdrq === 1 ? '关闭' : '开启'" placement="top">
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.qdrq === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="USP输入电压">
        <template slot-scope="scope">
          <span>{{ scope.row.qdrq }}V</span>
        </template>
      </el-table-column>
      <el-table-column label="USP输出电压" prop="qdrq">
        <template slot-scope="scope">
          <span>{{ scope.row.qdrq }}V</span>
        </template>
      </el-table-column>
      <el-table-column prop="qdrq" label="UPS负载率">
        <template slot-scope="scope">
          <span>{{ scope.row.qdrq }}%</span>
        </template>
      </el-table-column>
      <el-table-column prop="qdrq" label="USP温度">
        <template slot-scope="scope">
          <span>{{ scope.row.qdrq }}°</span>
        </template>
      </el-table-column>
      <el-table-column prop="qdrq" label="服务灯检">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="scope.row.qdrq === 1 ? '故障' : '正常'" placement="top">
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.qdrq === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="qdrq" label="储存灯检">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="scope.row.qdrq === 1 ? '故障' : '正常'" placement="top">
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.qdrq === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="qdrq" label="巡检部门"></el-table-column>
      <el-table-column prop="qdrq" label="巡检人" min-width="50"></el-table-column>
      <el-table-column prop="qdrq" label="巡检单" min-width="50">
        <template slot-scope="scope">
          <el-image style="width: 45px; height: 45px" :src="scope.row.htsmj[0]" :preview-src-list="scope.row.htsmj">
            <div slot="error">
              <img style="width: 100%" src="@/assets/images/shan.jpg" alt />
            </div>
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="巡检时间" width="100">
        <template slot-scope="scope">{{ scope.row.tjsj | dateFormat }}</template>
      </el-table-column>
      <el-table-column label="添加时间" width="100">
        <template slot-scope="scope">{{ scope.row.tjsj | dateFormat }}</template>
      </el-table-column>
      <el-table-column label="操作" align="right" min-width="120">
        <template slot-scope="scope">
          <el-button type="text" class="Btn_nan" @click="addUser('编辑机房巡检单', scope.row)">编辑</el-button>
          <span class="operation"></span>
          <el-button type="text" class="Btn_nan" @click="userBox(scope.row)">详情</el-button>
          <span class="operation"></span>
          <el-button type="text" size="small" class="delete Btn_nan" @click="deteleJD(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="fooer_box">
      <div></div>
      <el-pagination
        background
        small
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[1, 5, 10, 15]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next"
        :total="countList"
      ></el-pagination>
    </div>
    <!-- 卡口详情 -->
    <el-dialog title="卡口详情" :visible.sync="contractDialogVisible">
      <div class="dialogText">
        <el-row>
          <el-col :span="10" class="lineHight">
            <el-row>
              <span class="contentFont"> <span class="star">*</span>卡口名称： </span>
            </el-row>
            <el-row>
              <span class="contentFont"> <span class="star">*</span>卡口编号： </span>
            </el-row>
            <el-row>
              <span class="contentFont"> <span class="star">*</span>签订日期： </span>
            </el-row>
            <el-row>
              <span class="contentFont"> <span class="star">*</span>验收日期： </span>
            </el-row>
            <el-row>
              <span class="contentFont"> <span class="star">*</span>维保期限： </span>
              <el-tag>月</el-tag>
            </el-row>
            <el-row>
              <span class="contentFont">项目名称：</span>
            </el-row>
            <el-row>
              <span class="contentFont">合同金额：</span>
              <span style="color: #e6a23c"></span>
            </el-row>
            <el-row>
              <span class="contentFont">合同扫描件：</span>
              <el-image style="width: 35px; height: 40px" :src="contractList[0].htsmj[0]" :preview-src-list="contractList[0].htsmj">
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline"></i>
                </div>
              </el-image>
            </el-row>
          </el-col>
          <el-col :span="10" class="lineHight">
            <el-row>
              <span class="contentFont">甲方：</span>
            </el-row>
            <el-row>
              <span class="contentFont">甲方联系人：</span>
            </el-row>
            <el-row>
              <span class="contentFont">甲方联系电话：</span>
            </el-row>
            <el-row>
              <span class="contentFont">乙方：</span>
            </el-row>
            <el-row>
              <span class="contentFont">乙方联系人：</span>
            </el-row>
            <el-row>
              <span class="contentFont">乙方联系电话：</span>
            </el-row>
          </el-col>
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="contractDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="contractDialogVisible = false">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 删除 -->
    <el-dialog title="删除" :visible.sync="dialogVisibleDetele" width="30%">
      <span>您确定要删除吗？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleDetele = false">取 消</el-button>
        <el-button type="primary" @click="deleteItem">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { pinT } from '@/utils/allUrl.js'
// import { endLoading } from '@/utils/loading.js'
export default {
  data: function () {
    return {
      value: '',
      contractName: '',
      currentPage: 1,
      pageSize: 10,
      contractList: [
        {
          qdrq: '1',
          htsmj: [
            'https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1594030281&di=181374acea5d2bdca0585c34c765f9f0&src=http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg',
          ],
        },
      ],
      countPage: 0,
      countList: 0,
      // 机构
      jgmcOptions: [],
      contractDialogVisible: false, // 详情
      dialogVisibleDetele: false, // 删除
      searchBox: {
        ssjg: '',
        xjsj: '',
        searchValue: '',
      },
      pickerBeginDateBefore: {
        // 设置只能选择到今天及以前的日期
        disabledDate(time) {
          return time.getTime() >= Date.now()
        },
      },
      tiText1: '暂无数据', // 机构提示
    }
  },
  created: function () {
    // endLoading()
    this.getContractList()
    // 获取所属机构
    this.getMechanism()
  },
  methods: {
    // 获取数据
    async getContractList() {
      // const a = setTimeout(() => {
      //   endLoading()
      // }, 30000)
      const params = new URLSearchParams()
      params.append('M_', this.currentPage)
      params.append('N_', this.pageSize)
      const { data: res } = await this.$http.post(`${pinT}htgl/list`, params)
      // clearTimeout(a)
      // endLoading()
      if (res.code === '0014') {
        return ''
      } else if (res.code === '0013') {
        return (this.contractList = [])
      } else if (res.code !== '0000') {
        return this.$message({
          type: 'error',
          message: res.message,
          center: true,
        })
      }
      res.data.list.forEach((item) => {
        if (item.htsmj === null) {
          item.htsmj = ''
        }
        item.htsmj = item.htsmj.split('_')
      })
      // this.countList = res.data.countList
      // this.contractList = res.data.list
    },
    // 获取机构
    async getMechanism() {
      const { data: res } = await this.$http.post(`${pinT}zzjg/list`)
      if (res.code !== '0000') {
        this.jgmcOptions = []
        this.tiText1 = res.message
      } else {
        const a = JSON.stringify(res.data.list)
        const newCity = a.replace(/id/g, 'value')
        const cityList = newCity.replace(/jgmc/g, 'label')
        const cityList2 = cityList.replace(/jgbmmc/g, 'label')
        const c = cityList2.replace(/bmList/g, 'children')
        this.jgmcOptions = JSON.parse(c)
      }
    },
    handleSizeChange(e) {
      this.currentPage = 1
      this.pageSize = e
      this.getContractList()
    },
    handleCurrentChange(e) {
      this.currentPage = e
      this.getContractList()
    },
    addUser(title, scope) {
      if (title === '录入机房巡检单') {
        this.$router.push({
          name: 'addMachineInspection', // 路由
          params: {
            // 传递参数
            title: title,
          },
        })
      } else {
        this.$router.push({
          name: 'addMachineInspection', // 路由
          params: {
            // 传递参数
            title: title,
            content: scope,
          },
        })
      }
    },
    // 详情
    userBox(scope) {
      this.contractDialogVisible = true
    },
    // 删除
    deteleJD(scope) {
      this.dialogVisibleDetele = true
    },
    deleteItem() {
      this.dialogVisibleDetele = false
    },
    // async onSubmit() {
    //   const params = new URLSearchParams()
    //   params.append('htmc', this.queryCondition)
    //   params.append('M_', this.currentPage)
    //   params.append('N_', this.pageSize)
    //   const { data: res } = await this.$http.post(`${pinT}htgl/list`, params)
    //   if (res.code === '0013') {
    //     return (this.contractList = [])
    //   } else if (res.code !== '0000') {
    //     return this.$message({
    //       type: 'error',
    //       message: res.message,
    //       center: true
    //     })
    //   }
    //   res.data.list.forEach(item => {
    //     if (item.htsmj === null) {
    //       item.htsmj = ''
    //     }
    //     item.htsmj = item.htsmj.split('_')
    //   })

    //   this.countList = res.data.countList
    //   this.contractList = res.data.list
    // },
  },
}
</script>
<style lang="scss" scoped>
.addMargin {
  .increased {
    float: left;
    padding: 0 10px;
    height: 35px;
    line-height: 35px;
    margin: 15px 15px 0 0;
    background: rgba(103, 194, 58, 1);
    font-size: 14px;
    color: #fff;
    text-align: center;
  }
  .formLine {
    margin: 15px 0;
    float: left;
    .formLine_item {
      padding: 0;
      margin-bottom: 10px;
    }
  }
}
.addMargin:after {
  content: '';
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}
.el-table {
  border: 1px solid #eaeaea;
  border-bottom: 0;
  .operation {
    display: inline-block;
    margin: 0 5px;
    height: 10px;
    border-left: 1px solid #b3b3b3;
  }
  .Btn_nan {
    padding: 0;
  }
}
.fooer_box {
  height: 48px;
  line-height: 47px;
  padding: 0 15px;
  box-sizing: border-box;
  border-top: none;
  border: 1px solid #eaeaea;
  border-top: 0;
  display: flex;
  justify-content: space-between;
  .el-pagination {
    padding: 6px 5px;
  }
}
.delete {
  color: #f56c6c;
}
.dialogText {
  font-size: 14px;
  color: #333;
  .star {
    color: #f56c6c;
  }
  .contentFont {
    display: inline-block;
    width: 103px;
    color: #7a7a7a;
    text-align: right;
  }
  .lineHight .el-row {
    line-height: 40px;
    border: none;
  }
}
</style>
